﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DAL;
using DAL.Models;
using BAL;
using BAL.Interfaces;
using BibliotecaVirtual.Models;

namespace BibliotecaVirtual.Controllers
{
    [Authorize(Roles = Libreria.Constantes.ADMINISTRADOR)]
    public class TemaController : Controller
    {
        private ITemasService BALTemas = null;

        public TemaController(ITemasService TemasService)
        {
            BALTemas = TemasService;
        }

        //
        // GET: /Tema/
        public ViewResult Index()
        {
            return View(BALTemas.GetAllValidados());
        }

        //
        // GET: /Tema/Details/5
        public ViewResult Details(long id)
        {
            object[] keys = { id };
            Temas tema = BALTemas.Find(keys);
            return View(tema);
        }

        //
        // GET: /Tema/Create
        public ActionResult Create()
        {
            return View();
        } 

        //
        // POST: /Tema/Create

        [HttpPost]
        public ActionResult Create(Temas item)
        {
            if (ModelState.IsValid)
            {
                BALTemas.Create(item);
                return RedirectToAction("Index");  
            }

            return View(item);
        }
        
        //
        // GET: /Tema/Edit/5
        public ActionResult Edit(long id)
        {
            object[] keys = { id };
            Temas tema = BALTemas.Find(keys);
            return View(tema);
        }

        //
        // POST: /Tema/Edit/5

        [HttpPost]
        public ActionResult Edit(Temas item)
        {
            if (ModelState.IsValid)
            {
                BALTemas.Edit(item);
                return RedirectToAction("Index");
            }
            return View(item);
        }

        //
        // GET: /Tema/Delete/5
        public ActionResult Delete(long id)
        {
            object[] keys = { id };
            Temas tema = BALTemas.Find(keys);
            return View(tema);
        }

        //
        // POST: /Tema/Delete/5

        [HttpPost, ActionName("Delete")]
        public ActionResult DeleteConfirmed(long id)
        {
            object[] keys = { id };
            Temas tema = BALTemas.Find(keys);
            BALTemas.Remove(tema);
            return RedirectToAction("Index");
        }

        //protected override void Dispose(bool disposing)
        //{
        //    BALTemas.Dispose();
        //    base.Dispose(disposing);
        //}
    }
}